home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-10-04 | 10.3 KB | 369 lines | [TEXT/ttxt] |
- { ClickLoc FKEY © 1991-92 by Jon Wind }
- { Version 1.0 on 1/4/91 }
- { Version 1.1 on 6/20/91 }
- { Version 2.0 on 10/4/92 }
-
- { This FKEY lets you draw a rectangle on the screen and displays it's coordinates. }
-
- { Thanks to Brad Pettit and his colorfkey for his method of conditional compilation. }
-
- { To execute this as a program... }
- { 1. change the definition of fkey to false }
- { 2. set the project type to application }
- { 3. change the library from drvrruntime.lib to µruntime.lib }
- { 4. rebuild the project}
-
-
- {$setc fkey := true}
-
- {$ifc fkey}
-
- unit ClickLocFKEY;
-
- interface
-
- procedure main;
-
- implementation
-
- {$elsec}
-
- program ClickLocFKEY;
-
- {$endc}
-
- procedure main;
- const
- vers = 'v2.0';
- enterKey = 3;
- lastValIndex = 5;
- bCommandKey = 48;
- bShiftKey = 63;
- bControlKey = 60;
- bOptionKey = 61;
- bCapsLockKey = 62;
- gridSize = 50;
- MarqueeDelay = 2;
- type
- myIntArray = array[0..lastValIndex] of Integer;
- myLabelArray = array[0..lastValIndex] of string[7];
- var
- dlgPtr: DialogPtr;
- theRect, oldRect, menuRect: Rect;
- savePort: GrafPtr;
- CMenuPtr: MCEntryPtr;
- p: grafport;
- itmHdl: Handle;
- theEvent: EventRecord;
- done, usingColor, hasLocal, useLocal, hasGrid: Boolean;
- grayPat, gridPat, marqueePat: Pattern;
- startPoint, endPoint: Point;
- h, i, theFont, baseLine, menuHeight: Integer;
- IntPtr: ^Integer;
- lastDraw: LongInt;
- LabelArray: myLabelArray;
- oldIntArray, IntArray, WidthArray: myIntArray;
- CrossCursHndl: CursHandle;
- theStr: string[25];
- fInfo: FontInfo;
-
-
- function GetMBarHeight: Integer;
- { get current menu bar height }
- var
- thePtr: ^Integer;
- begin
- thePtr := Pointer($BAA);
- GetMBarHeight := thePtr^;
- end; { of func GetMBarHeight }
-
- function IsColor: Boolean;
- { return true if using 16 or more "colors" }
- var
- maindevice: GDHandle;
- theWorld: SysEnvRec;
- begin
- IsColor := False;
- if (SysEnvirons(1, theWorld) <> envNotPresent) then { SysEnvirons call available? }
- if theWorld.hasColorQD then { has Color QuickDraw }
- begin
- maindevice := GetMainDevice;
- IsColor := (maindevice^^.gdPMap^^.pixelsize > 2); { 16 or more shades? }
- end;
- end;{ of func IsColor }
-
- function myGetGrayRgn: Handle;
- { get current gray region }
- var
- thePtr: ^Handle;
- begin
- thePtr := Pointer($9EE);
- myGetGrayRgn := thePtr^;
- end; { of func GetGrayRgn }
-
- function GetKeyDown (index: Integer): Boolean;
- { return the state of the desired key - true if down; false if up }
- var
- keys: keymap;
- begin
- GetKeys(keys);
- GetKeyDown := bittst(@keys, index); { look at entry within the key map }
- end;
-
- procedure DoDrawGrid;
- { get current menu bar height }
- var
- i: Integer;
- thePen: PenState;
- begin
- GetPenState(thePen); { save current pen }
- PenPat(gridPat);
- for i := 1 to p.visRgn^^.RgnBBox.right div gridSize do
- begin
- MoveTo(i * gridSize, menuRect.bottom + 2);
- LineTo(i * gridSize, p.visRgn^^.RgnBBox.bottom);
- end;
- for i := 1 to p.visRgn^^.RgnBBox.bottom div gridSize do
- begin
- MoveTo(p.visRgn^^.RgnBBox.left, i * gridSize);
- LineTo(p.visRgn^^.RgnBBox.right, i * gridSize);
- end;
- SetPenState(thePen); { restore old pen }
- hasGrid := not hasGrid;
- end; { of proc DoDrawGrid }
-
- function aNum2Str (aNum: LongInt): Str255;
- { NumToString procedure available as a function }
- var
- NumStr: Str255;
- begin
- NumToString(aNum, NumStr);
- aNum2Str := NumStr;
- end;
-
- procedure rotateByte (p: Ptr);
- inline
- $205F, $1010, $E218, $1080;
- { move.l (sp)+,a0}
- { move.b (a0),d0}
- { ror.b #1,d0}
- { move.b d0,(a0)}
-
-
- procedure DrawMarquee (oldRect, newRect: Rect);
- var
- i: Integer;
- begin
- lastDraw := TickCount;
- for i := 0 to 7 do { set up blinking marquee pattern by shifting bits }
- rotateByte(@marqueePat[i]);
- FrameRect(oldRect); { erase old rect }
- PenPat(marqueePat);
- FrameRect(newRect); { draw new rect }
- end; { of proc DrawMarquee }
-
-
-
- { --------- Main Procedure --------- }
- begin
- GetPort(savePort); { save current grafport }
-
- hasLocal := (FrontWindow <> nil);
- {• if not hasLocal then•}
- {• sysbeep(1);•}
-
- StuffHex(@grayPat, 'AA55AA55AA55AA55');
- StuffHex(@gridPat, '55FF77FF55FF77FF');
- StuffHex(@marqueePat, '0F1E3C78F0E1C387');
-
- SetRect(oldRect, 0, 0, 0, 0);
- LabelArray[0] := 'Left:';
- LabelArray[1] := 'Top:';
- LabelArray[2] := 'Right:';
- LabelArray[3] := 'Bottom:';
- LabelArray[4] := 'Height:';
- LabelArray[5] := 'Width:';
- done := False;
- hasGrid := False;
- lastDraw := 0;
- for i := 0 to lastValIndex do
- IntArray[i] := 0;
-
- CrossCursHndl := GetCursor(crosscursor);
- MoveHHi(Handle(CrossCursHndl));
- HLock(Handle(CrossCursHndl));
-
- usingColor := IsColor;
- if usingcolor then
- begin
- OpenCPort(@p); { open as current port }
- CMenuPtr := GetMCEntry(0, 0);
- if CMenuPtr <> nil then
- begin
- RGBForeColor(CMenuPtr^.mctRGB1);
- RGBBackColor(CMenuPtr^.mctRGB4);
- end;
- end
- else
- OpenPort(@p); { open as current port }
-
- GetFNum('Geneva', theFont);
- TextFont(theFont);
- TextSize(9);
- GetFontInfo(fInfo);
- menuHeight := GetMBarHeight;
- baseLine := Pred(((menuHeight - (fInfo.ascent + fInfo.descent)) div 2) + fInfo.ascent);
- SetRect(menuRect, 1, 0, p.portrect.right, menuHeight - 1);
- EraseRoundRect(menuRect, 12, 12);
-
- PenPat(grayPat);
- PenMode(notPatXor); { allows easy redrawing of gray frames }
- UnionRgn(p.visRgn, RgnHandle(myGetGrayRgn), p.visRgn); { adjust new port to allow drawing on all screens }
- UnionRgn(p.clipRgn, RgnHandle(myGetGrayRgn), p.clipRgn); { adjust new port to allow drawing on all screens }
-
- TextFace([bold]);
- Moveto(6, baseLine);
- DrawString('ClickLoc FKEY by Jon Wind.');
- TextFace([]);
- DrawString(' Click & drag. Caps Lock for grid. Press a key to end.');
-
- if hasLocal then
- dlgPtr := FrontWindow;
-
- repeat
- repeat
- if (GetKeyDown(bCapsLockKey) and not hasGrid) or (hasGrid and not GetKeyDown(bCapsLockKey)) then
- DoDrawGrid;
-
- if (TickCount >= lastDraw + MarqueeDelay) then {& not EmptyRect(oldRect)}
- DrawMarquee(oldRect, oldRect);
-
- SetCursor(CrossCursHndl^^);
- until GetOSEvent(EveryEvent, theEvent);
- case theEvent.what of
- autokey, keyDown:
- begin
- done := True;
- if BitAnd(theEvent.message, CharCodeMask) = enterKey then { copy to scrap if Enter key pressed }
- begin
- theStr := Concat(aNum2Str(IntArray[0]), ',', aNum2Str(IntArray[1]), ',', aNum2Str(IntArray[2]), ',', aNum2Str(IntArray[3]));
- if ZeroScrap = noErr then
- lastDraw := PutScrap(Length(theStr), 'TEXT', Pointer(@theStr[1]));
- end;
- end;
- mouseDown:
- begin
- useLocal := hasLocal & (GetKeyDown(bShiftKey) or GetKeyDown(bCommandKey) or GetKeyDown(bOptionKey) or GetKeyDown(bControlKey));
- if useLocal then
- begin
- SetPort(dlgPtr); { restore grafport to front window }
- GetMouse(startPoint);
- SetPort(@p); { restore grafport }
- end
- else
- GetMouse(startPoint);
-
- FrameRect(oldRect); { erase old rect }
- EraseRoundRect(menuRect, 12, 12); { clear menu bar area }
- SetRect(oldRect, 0, 0, -1, -1);
- TextFace([bold]);
- moveto(menuRect.left + 10, baseLine);
- if useLocal then
- DrawString('L')
- else
- DrawString('G');
- moveto(35, baseLine);
- for i := 0 to lastValIndex do
- begin
- WidthArray[i] := StringWidth(LabelArray[i]);
- DrawString(LabelArray[i]);
- move(36, 0);
-
- oldIntArray[i] := maxint;
- end;
- TextFace([]);
- MoveTo(menuRect.right - StringWidth(Vers) - 5, baseLine);
- DrawString(Vers);
-
- repeat
- if useLocal then
- SetPort(dlgPtr); { restore grafport }
-
- GetMouse(endPoint);
-
- if (endPoint.h >= startPoint.h) and (endPoint.v >= startPoint.v) then
- SetRect(theRect, startPoint.h, startPoint.v, endPoint.h, endPoint.v)
- else if (endPoint.h > startPoint.h) and (endPoint.v < startPoint.v) then
- SetRect(theRect, startPoint.h, endPoint.v, endPoint.h, startPoint.v)
- else if (endPoint.h < startPoint.h) and (endPoint.v > startPoint.v) then
- SetRect(theRect, endPoint.h, startPoint.v, startPoint.h, endPoint.v)
- else
- SetRect(theRect, endPoint.h, endPoint.v, startPoint.h, startPoint.v);
-
- IntArray[0] := theRect.left;
- IntArray[1] := theRect.top;
- IntArray[2] := theRect.right;
- IntArray[3] := theRect.bottom;
- IntArray[4] := theRect.bottom - theRect.top;
- IntArray[5] := theRect.right - theRect.left;
-
- if useLocal then
- begin
- SetPort(dlgPtr); { restore grafport }
- LocalToGlobal(theRect.topLeft);
- LocalToGlobal(theRect.botRight);
- SetPort(@p); { restore grafport }
- end;
-
- if not EqualRect(oldRect, theRect) then
- begin
- DrawMarquee(oldRect, theRect);
-
- h := 0;
- for i := 0 to lastValIndex do
- begin
- h := h + WidthArray[i];
- SetRect(oldRect, 37 + (36 * i) + h, menuRect.top, (36 * i) + h + 65, menuRect.bottom);
- moveto(oldRect.left, baseLine);
- if IntArray[i] <> oldIntArray[i] then
- begin
- EraseRect(oldRect);
- DrawString(aNum2Str(IntArray[i]));
- oldIntArray[i] := IntArray[i];
- end;
- end;
-
- oldRect := theRect; { save current rect for later erasure }
- end;
-
- if (TickCount >= lastDraw + MarqueeDelay) then
- DrawMarquee(oldRect, oldRect);
- until not StillDown;
- end;
- otherwise
- end;
- until done;
-
- FrameRect(oldRect); { erase old rect }
- if hasGrid then
- DoDrawGrid; { erase old grid }
- if usingcolor then
- CloseCPort(@p)
- else
- ClosePort(@p);
- InitCursor;
- HUnLock(Handle(CrossCursHndl));
- {• ReleaseResource(Handle(CrossCursHndl));•}
- SetPort(savePort); { restore grafport }
- DrawMenuBar; { fix menubar }
- end; { main }
-
-
- {$ifc fkey = false}
-
- begin
- main;
-
- {$endc}
-
- end.